package CinemaDevelop;
import java.util.ArrayList;
import java.util.List;

public class Cinema {
    private String name;
    private List<ScreenRoom> rooms;
    private List<MovieSchedule> movieSchedules;

    public Cinema(String name) {
        this.name = name;
        this.rooms = new ArrayList<>();
        this.movieSchedules = new ArrayList<>();
        loadFromDatabase();
    }

    private void loadFromDatabase() {
        this.rooms = CinemaDAO.getAllScreenRooms();
        this.movieSchedules = CinemaDAO.getAllMovieSchedules();


        for (MovieSchedule schedule : movieSchedules) {
            List<CinemaDAO.Seat> seats = CinemaDAO.getSeatsForSchedule(schedule.getScheduleId());
            for (CinemaDAO.Seat seat : seats) {
                if ("OCCUPIED".equals(seat.getStatus())) {
                    schedule.getRoom().sc.add(seat.getRow(), seat.getCol(), seat.getCustomerInfo());
                }
            }
        }
    }

    public void setMovieSchedules(MovieSchedule movieSchedule) {
        movieSchedules.add(movieSchedule);
    }

    public void setScreenRooms(ScreenRoom room) {
        rooms.add(room);
    }

    public List<MovieSchedule> getMovieSchedules() {
        return movieSchedules;
    }

    public void findMovie(String movieName) {
        boolean found = false;
        for (MovieSchedule schedule : movieSchedules) {
            if (schedule.getMovie().name.equals(movieName)) {
                found = true;
                System.out.println("放映厅：" + schedule.getRoom().type + "  观影时间" + schedule.getTime());
            }
        }
        if (!found) {
            System.out.println("未安排该电影");
        }
    }

    public String getName() {
        return name;
    }

    public List<ScreenRoom> getRooms() {
        return rooms;
    }
}


